package cn.growthgate.fgo.entity;

import java.io.Serializable;
import java.util.Date;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;

import cn.growthgate.fgo.entity.enums.UserClient;
import cn.growthgate.fgo.entity.enums.Sex;
import cn.growthgate.fgo.entity.enums.UserStatus;
import cn.growthgate.fgo.util.RegularUtils;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author GrowthGate
 * @since 2019-01-20
 */
@TableName("t_sys_user")
public class User extends Model<User> {

	private static final long serialVersionUID = 1L;

	/**
	 * 主键id
	 */
	@TableId(value = "id", type = IdType.AUTO)
	private Long id;

	/**
	 * 头像
	 */
	private String avatar;

	/**
	 * 用户名
	 */
	@Size(min = 4, max = 20, message = "用户名必须大于4位且小于20位", groups = Register.class)
	@Pattern(regexp = RegularUtils.REGEN_USERNAME, message = "用户名只能由英文字母、数字和下划线组成"
			, groups = {Register.class, Create.class, Update.class})
	@NotBlank(message = "用户名不能为空", groups = {Register.class, Login.class})
	private String username;

	/**
	 * 密码
	 */
	@Min(value = 6, message = "密码必须大于6位", groups = Register.class)
	@NotBlank(message = "密码不能为空", groups = {Register.class, Login.class})
	@JSONField(serialize = false)
	private String password;

	/**
	 * 密码盐
	 */
	@JSONField(serialize = false)
	private String salt;

	/**
	 * 昵称
	 */
	@NotBlank(message = "昵称不能为空", groups = {Register.class, Create.class, Update.class})
	private String name;

	/**
	 * 性别
	 */
	@NotNull(message = "性别不能为空", groups = {Create.class, Update.class})
	private Sex sex;

	/**
	 * 客户端
	 */
	private UserClient client;
	
	/**
	 * py码
	 */
	private String pyCode;
	
	/**
	 * 状态
	 */
	@NotNull(message = "状态不能为空", groups = Create.class)
	private UserStatus status;

	/**
	 * 添加时间
	 */
	private Date addtime;

	/**
	 * 最后登录时间
	 */
	private Date lastLoginTime;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Sex getSex() {
		return sex;
	}

	public void setSex(Sex sex) {
		this.sex = sex;
	}

	/**
	 * @return client
	 */
	public UserClient getClient() {
		return client;
	}

	/**
	 * @param client 要设置的 client
	 */
	public void setClient(UserClient client) {
		this.client = client;
	}

	/**
	 * @return pyCode
	 */
	public String getPyCode() {
		return pyCode;
	}

	/**
	 * @param pyCode 要设置的 pyCode
	 */
	public void setPyCode(String pyCode) {
		this.pyCode = pyCode;
	}

	public UserStatus getStatus() {
		return status;
	}

	public void setStatus(UserStatus status) {
		this.status = status;
	}

	public Date getAddtime() {
		return addtime;
	}

	public void setAddtime(Date addtime) {
		this.addtime = addtime;
	}

	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	@Override
	protected Serializable pkVal() {
		return this.id;
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", avatar=" + avatar + ", username=" + username + ", password=" + password + ", salt="
				+ salt + ", name=" + name + ", sex=" + sex + ", client=" + client + ", pyCode=" + pyCode + ", status="
				+ status + ", addtime=" + addtime + ", lastLoginTime=" + lastLoginTime + "]";
	}

	public interface Login{}
	public interface Register{}
	public interface Create{}
	public interface Update{}

}
